package homework.hw2;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * @Author Administrator
 * @Date 2020/5/21 15:33
 **/
@WebServlet("/forwardAndRedirect2")
public class ForwardAndRedirect2 extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        /*显示内容：
        1.通过响应response对象：获取输出流，通过输出流写数据
        2.通过域对象，获取保存在域对象中的内容
         */

        //Object user = req.setAttribute("user");

        resp.setContentType("text/html;charset=utf-8");
        Object user = req.getSession().getAttribute("user");
        PrintWriter pw = resp.getWriter();
        pw.write("gun 不准看"+user);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doGet(req,resp);
    }
}
